package com.zj.study;

public class 最长回文子串_暴力破解 {

    public static void main(String[] args) {
        System.out.println(longestPalindrome("cbbd"));
    }

    public static boolean isPalindromic(String s) {
        int len = s.length();
        for (int i = 0; i < len / 2; i++) {
            if (s.charAt(i) != s.charAt(len - i - 1)) {
                return false;
            }
        }
        return true;
    }

    public static String longestPalindrome(String s) {
        for (int len = s.length(); len > 1; len--) {
            for (int start = 0; start < s.length() - 1; start++) {
                int end = start + len - 1;
                if (end < s.length()) {
                    String sub = s.substring(start, end);
                    if (isPalindromic(sub)) {
                        return sub;
                    }
                }
            }
        }
        return s.substring(0, 1);
    }


}
